<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title th:text="${shop.name+'-订单管理'}"></title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;">
    <style type="text/css">
        .update {
            display: inline-block;
            margin-left: 15px;
            padding: 0 20px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            background: #009789;
            color: #fff;
            text-align: center;
            border-radius: 3px;
            cursor: pointer;
        }

        .update i {
            display: inline-block;
            margin-right: 10px;
            vertical-align: middle;
            width: 30px;
            height: 30px;
            background: url();
        }
        .T-box {
            width: 400px;
            padding: 0 20px;
            text-align: left;
        }

        .T-box p {
            position: relative;
            height: 36px;
            line-height: 36px;
            font-size: 14px;
            margin-bottom: 15px;
        }

        .T-box p span {
            display: inline-block;
            padding-right: 15px;
            text-align: right;
            width: 110px;
            line-height: 36px;
            font-size: 14px;
        }

        .T-box p input, .T-box p select {
            width: 250px;
            padding: 0 5px;
            height: 34px;
            line-height: 34px;
            font-size: 14px;
            border: 1px solid #d3d3d3;
            outline: none;
        }

        .T-box p i {
            padding: 0 10px;
            line-height: 36px;
            font-style: normal;
        }

        .T-box p b {
            display: inline-block;
            margin-left: 10px;
            cursor: pointer;
            width: 60px;
            height: 36px;
            line-height: 36px;
            background: #c33;
            color: #fff;
            text-align: center;
            font-size: 13px;
            font-weight: normal;
        }
    </style>
    <div class="layui-tab layui-tab-brief" lay-filter="demo">
        <ul class="layui-tab-title">
            <li><a th:href="@{/shop/dashboard(shopId=${shopId})}">店铺首页</a></li>
            <li class="layui-this"><a th:href="@{/xhs/order_list(shopId=${shopId})}">订单管理</a></li>
            <li ><a th:href="@{/xhs/goods_list(shopId=${shopId})}">商品管理</a></li>
            <li><a class="order-item" th:href="@{/xhs/refund_list(shopId=${shopId})}">退货管理</a></li>
            <li><a href="/shop/shop_list_xhs" style="color: #9F9F9F;font-size:small;">选择店铺</a></li>
        </ul>
    </div>

    <!-- content starts -->
<!--    <blockquote class="layui-elem-quote">订单总览</blockquote>-->

    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
<!--            <div class="layui-inline">-->
<!--                <form method="post" enctype="multipart/form-data" id="execl_form">-->
<!--                    <input type="file" name="excel" id="excel" placeholder="" class="layui-input">-->
<!--                </form>-->
<!--            </div>-->

<!--            <div class="layui-inline">-->
<!--                <button type="button" id="excel_upload_btn" class="layui-btn">上传excel</button>-->
<!--                <span id="excel_upload_btn_" style="display: none;" class="update"><i></i>导入中</span>-->
<!--            </div>-->
            <form class="layui-form layui-form-pane1" method="get" action="/xhs/order_list">
                <input type="hidden" name="shopId" th:value="${shop.id}" />
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="orderNum" th:value="${orderNum}" placeholder="订单编号" style="width: 200px;" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">下单时间</label>
                        <div class="layui-input-inline">
                            <input type="text"   class="layui-input" name="startTime" th:value="${startTime}" id="startTime" autocomplete="off"
                                  style="width: 160px;" placeholder="yyyy-MM-dd">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text"  class="layui-input" name="endTime" th:value="${endTime}" id="endTime" style="width: 160px;" autocomplete="off" placeholder="yyyy-MM-dd">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="logisticsCode" th:value="${logisticsCode}" placeholder="物流单号" style="width: 200px;" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="status" id="status">
                                <option value="">订单状态</option>
                                <option th:each="item:${T(com.b2c.entity.enums.EnumXhsOrderStatus).values()}" th:value="${item.getIndex()}" th:text="${item.getName()}">等待发货</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-normal">搜索</button>
                        <i>总共：<span style="color: red" th:text="${totalSize}"></span>条记录</i>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <span id="upd_order" class="layui-btn layui-btn-normal" th:attr="shopId=${shop.getId()}">更新小红书订单数据</span>
                        <span id="upd_order_" style="display: none;" class="update"><i></i>更新中</span>
                    </div>

                    <div class="layui-inline">
                        <button type="button" lass="button" id="excel_btn" class="layui-btn layui-btn-primary">导出订单</button>
                    </div>

                    <div class="layui-inline">
                        <span id="confirm_order" class="layui-btn layui-btn-disabled">批量确认（抖单打单)</span>
                        <span id="confirm_order_" style="display: none;" class="update"><i></i>批量确认中</span>
                    </div>
<!--                    <div class="layui-inline">-->
<!--                        <a  target="_blank" th:href="@{/douyin/order_print_list(shopId=${shopId},print=0)}"  class="layui-btn layui-btn-normal">打单工具（电子面单）</a>-->
<!--                    </div>-->
                </div>


            </form>
        </div>
    </fieldset>

    <!-- start dd-wrapper -->
    <link rel="stylesheet" href="/goods/order.css"/>
    <div class="dd-wrapper">
        <table class="dd-table">
            <tr>
<!--                <th>ID</th>-->
                <th>订单号</th>
                <th width="25%">商品</th>
                <th>支付总金额</th>
                <th>订单信息</th>
                <th>发货信息</th>
                <th>订单状态</th>
                <th>操作</th>
            </tr>
            <tr th:each="item:${lists}">
<!--                <td th:text="${item.id }"></td>-->
                <td th:text="${item.orderId}"></td>
                <td>

                    <div th:each="it:${item.items}" >
                        <img th:src="${it.getItemImage()}">
                        <p style="float: left">
                            <p  th:text="${#strings.abbreviate(it.getItemName(),28)}"></p>
                            <p>
                                <i th:if="${!#strings.isEmpty(it.erpCode)}" th:text="${it.erpCode}"></i>
                                <i th:text="${it.getItemSpec()}"></i>
                            </p>

                            <p>数量：<b th:text="${it.quantity}"></b>
                            <span th:if="${it.totalRedDiscount > 0}">平台优惠：<span th:text="${#numbers.formatDecimal(new java.math.BigDecimal(it.totalRedDiscount).divide(100),1,'COMMA',2,'POINT')  }" style="color: #FD482C;font-size: larger;"></span></span>
                            </p>
                        </p>
                    </div>
                </td>
                <td>¥<span th:text="${#numbers.formatDecimal(new java.math.BigDecimal(item.totalPayAmount).divide(100),1,'COMMA',2,'POINT')  }" style="color: #FD482C;font-size: larger;"></span></td>
                <td>
                    <div>
                        <p th:if="${!#strings.isEmpty(item.getCustomerRemark())}">买家备注:<b th:text="${item.getCustomerRemark()}"></b></p>
                        <p >卖家备注:<b class="sellerRemarkContent" th:text="${item.getSellerRemark()}"></b> <span th:attr="order-id=${item.getId()},remark=${item.getSellerRemark()}"  class="layui-btn-primary layui-btn-sm sellerRemark">备注</span></p>

                        <p th:text="${'下单时间：'+#dates.format(item.createdTime , 'yyyy-MM-dd HH:mm:ss')}"></p>
                        <p th:if="${item.getOrderStatus() == 4 }" style="color: #B23131" th:text="${'最晚发货时间：'+#dates.format(item.promiseLastDeliveryTime , 'yyyy-MM-dd HH:mm:ss')}"></p>
                    </div>
                </td>
                <td>
                    <div th:if="${item.getOrderStatus() == 4}">
                        <span th:attr="data-id=${item.getId()},orderId=${item.getOrderId()},openAddressId=${item.getOpenAddressId()},shopId=${item.getShopId()}" class="layui-btn-primary layui-btn-sm upaddress">更新发货地址</span><br />
                        <span th:text="${item.receiver}"></span>
                        <span th:text="${item.phone}"></span>
                        <br/>
                        <span th:if="${#strings.isEmpty(item.address)}" th:text="${item.province}"></span>
                        <span th:if="${#strings.isEmpty(item.address)}" th:text="${item.city}"></span>
                        <span th:if="${#strings.isEmpty(item.address)}" th:text="${item.district}"></span><br th:if="${#strings.isEmpty(item.address)}" />
                        <span th:text="${item.address}"></span>
                    </div>
                    <div th:if="${item.getOrderStatus() == 6}">
                        <span  th:text="${item.province}"></span>
                        <span  th:text="${item.city}"></span>
                        <span  th:text="${item.district}"></span>
                        <p>
                        <span th:text="${item.getExpressCompanyCode()}"></span>:
                        <span th:text="${item.getExpressTrackingNo()}"></span>
                        </p>
                    </div>
                </td>

                <td>
                    <span th:text="${T(com.b2c.entity.enums.EnumXhsOrderStatus).getStatusName(item.getOrderStatus())}"></span><br />
                    <span th:text="${T(com.b2c.entity.enums.EnumXhsOrderAfterStatus).getStatusName(item.getAfterSalesStatus())}"></span><br />
                    <span th:text="${T(com.b2c.entity.enums.erp.EnumErpOrderSendStatus).getName(item.getErpSendStatus())}"></span>

                </td>
                <td>
                    <a th:href="@{/xhs/order_detail(id=${item.getId()},shopId=${shop.getId()})}">查看详情</a><br/>

                    <span th:if="${item.getErpSendStatus() == 0 && item.getOrderStatus() ==4 && item.getAfterSalesStatus()==1 }" th:attr="data-id=${item.getId()}" class="layui-btn layui-btn-normal layui-btn-sm order_confirm">确认到仓库</span>
                    <span th:if="${item.getOrderStatus()==4 && item.getAfterSalesStatus()==1 && item.getErpSendStatus() > 1 }" th:attr="data-id=${item.getId()}" class="layui-btn layui-btn-normal layui-btn-sm order_send" >订单发货</span>

                </td>
            </tr>
        </table>
    </div>
    <!-- end dd-wrapper -->
    <div class="layui-box layui-laypage layui-laypage-default pageBox">
        <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
    </div>
    <script type="text/template" id="send-goods">
        <div class="T-box">
            <p><span>快递公司</span>
                <select id="send-company">
                    <option value="">请选择快递公司</option>
                    <option th:each="item:${company}" th:selected="${item.isDefault == 1}" th:value="${item.getCode()}" th:text="${item.getName()}"></option>
                </select>
            </p>
            <p><span>快递单号</span><input type="text" name="express_code" autocomplete="off"/></p>
            <p class="T-result"><span>&nbsp;</span><em id="erro"></em></p>
        </div>
    </script>
    <script type="text/template" id="remarkBox">
        <div class="T-box">
            <p>
                <textarea name="remark" class="layui-textarea" id="remark" ></textarea>
            </p>
            <p class="T-result"><span>&nbsp;</span><em id="erro1"></em></p>
        </div>
    </script>
    <script type="text/javascript" src="/goods/Tips/Tips.min.js"></script>
    <script type="text/javascript">
        var layer;
        var $;
        var windowOpen;
        layui.use(['laydate', 'jquery', 'form', 'layer'], function () {
            var laydate = layui.laydate;
            $ = layui.jquery;
            var form = layui.form;
            layer = layui.layer;
            laydate.render({
                elem: '#startTime'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#endTime'
                ,type: 'datetime'
            });
            $(function () {
                var status = '[[${status}]]';
                $("#status").val(status);
                form.render(); //更新全部
                form.render('select'); //刷新select选择框渲染
            })

                $("#upd_order").click(function () {
                    $("#upd_order").hide();
                    $("#upd_order_").show();
                    let startTime = $("#startTime").val();
                    let endTime = $("#endTime").val();
                    let shopId=$(this).attr("shopId");
                    let data = {
                        startTime:startTime,
                        endTime:endTime,
                        shopId:shopId
                    };
                    $.ajax({
                        url: "/xhs/pull_order_ajx",
                        type: "POST",
                        dataType: "JSON",
                        data:JSON.stringify(data),
                        contentType: 'application/json',
                        success: function (res) {
                            if (res.code == 0) {
                                alert(res.msg);
                                location.reload(true);
                            }else {
                                Tips.alert(res.msg);
                            }
                            $("#upd_order").show();
                            $("#upd_order_").hide();
                        }
                    })
                });

            $(".order_confirm").click(function () {
                var obj = $(this);
                // $("#confirm_order").hide();
                // $("#confirm_order_").show();
                let data = {
                    orderId:$(this).attr('data-id')
                };
                $.ajax({
                    url: "/xhs/order_confirm",
                    type: "POST",
                    dataType: "JSON",
                    data:JSON.stringify(data),
                    contentType: 'application/json',
                    success: function (res) {
                        if (res.code == 0) {
                            obj.remove();
                            layer.msg("确认成功");
                            // location.reload(true);
                        }else {
                            Tips.alert(res.msg);
                        }
                        $("#confirm_order").show();
                        $("#confirm_order_").hide();
                    }
                })
            });

            $(".sellerRemark").click(function(){
                var id = $(this).attr('order-id');
                var remarkT = $(this).attr('remark');
                var obj = $(this).siblings('b').eq(0);

                layer.prompt({
                    formType: 2,
                    value: remarkT,
                    title: '请输入备注'
                }, function(value, index, elem){
                    var data = {id:id, remark:value};
                    $.ajax({
                        url: "/xhs/order_remark_ajax",
                        type: "POST",
                        dataType: "JSON",
                        contentType: 'application/json',
                        data:JSON.stringify(data),
                        success: function (res) {

                            if(res.code == 0){

                                $(obj).text(value);
                                layer.close(index)
                                layer.msg(res.msg);
                                // location=location;
                            }else
                                layer.alert(res.msg);
                        }
                    });


                });
            });
                //订单发货
                $(".order_send").click(function (e) {

                        e.stopPropagation();
                        e.preventDefault();
                        var id = $(this).attr('data-id');
                        Tips.confirm({
                            title: '手动填写物流信息',
                            content: $('#send-goods').html(),
                            define: function () {
                                var data = {
                                    id: id,
                                    company: $("#send-company  option:selected").text(),
                                    companyCode: $("#send-company  option:selected").val(),
                                    code: $("input[name='express_code']").val()
                                };
                                $.ajax({
                                    url: "/xhs/order_hand_send_ajax",
                                    type: "POST",
                                    dataType: 'json',
                                    contentType: 'application/json',
                                    data: JSON.stringify(data),
                                    success: function (res) {
                                        if (res.code == 0) {
                                            Tips.alert('成功', function () {
                                                location.reload(true);
                                            });
                                        } else {
                                            Tips.alert(res.msg);
                                        }
                                    }
                                });
                            }
                        });

                });

            //
            $(".upaddress").click(function () {
                var $this = $(this);
                var dataObj = {orderId: $this.attr("orderId"),id:$this.attr("data-id"),openAddressId:$this.attr("openAddressId"),shopId: $this.attr("shopId")}
                $.ajax({
                    url: "/xhs/pull_order_address_ajx",
                    type: "POST",
                    dataType: "JSON",
                    contentType: 'application/json',
                    data: JSON.stringify(dataObj),
                    success: function (res) {
                        if (res.code == 0) {
                            $this.parent().append(res.data);
                            layer.msg("收获地址拉取成功");
                            // location.reload();
                        }else if(res.code==601){
                            alert(res.msg);
                            try {
                                parent.location.href = res.data;
                            }catch (e) {
                                location.href = res.data;
                            }
                        }  else {
                            alert(res.msg);
                        }
                    }
                })
            });

            $("#excel_btn").click(function () {
                //组合条件
                var url = "/douyin/order_list_douyin_export";
                var startTime = $("input[name=startTime]").val();
                var endTime = $("input[name=endTime]").val();
                var status = $("#status").val();
                url+="?status="+status;
                if (startTime != '') {
                    url += "&startTime=" + startTime;
                }
                if (startTime != '') {
                    url += "&endTime=" + endTime;
                }
                window.open(url, "_blank");
            })

        });

    </script>

</div>
</body>
<html>
